﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
namespace Helper
{
    // this class to excute adding log comment to log file.
    //it's used for privating
   public class Log
    {
       static string logfile;
       static int day = DateTime.Now.Day;
       static int month = DateTime.Now.Month;
       static int year = DateTime.Now.Year;
       public static string AddLog(string logmessage)
       {
           logfile = Application.StartupPath + "\\DATA\\Log\\Logs_"+day +"_"+month+"_"+year+".log";
           logmessage=DateTime.Now.ToString() + "\n " + " Command: " + logmessage + "\r\n";
           try
           {
               string Uri = logfile;
               StreamWriter fileWriter = null;
               if (File.Exists(Uri))
               {
                   fileWriter = File.AppendText(Uri);
               }
               else
                   fileWriter = File.CreateText(Uri);
               try
               {
                   fileWriter.WriteLine(logmessage);
                   fileWriter.Flush();
               }
               finally
               {
                   fileWriter.Close();
               }

           }
           catch (Exception ex)
           {
               Console.WriteLine("Database Log Exception:" + ex.Message);
           }
           return logmessage;
       }
    }
}
